<?php

class Kd_Db_Config{

    private static $_conncetionSettings = array();
    private static $_defaultConnection = NULL;
    private static $_tablePrefix = '';
    
    public static function registerConnection($name, $driver, $server, $database, $username, $password, $isDefault = FALSE){
        self::$_conncetionSettings[$name] = array(
            'name'=>$name,
            'driver'=>$driver,
            'server'=>$server,
            'database'=>$database,
            'username'=>$username,
            'password'=>$password
        );
        if($isDefault){
            self::$_defaultConnection = $name;
        }
    }

    public static function getConnectionSetting($name){
        return self::$_conncetionSettings[$name];
    }

    public static function getConnectionSettings(){
        return self::$_conncetionSettings;
    }

    public static function getTablePrefix(){
        return self::$_tablePrefix;
    }

    public static function setTablePrefix($value){
        self::$_tablePrefix = $value;
    }

    public static function setDefaultConncection($connectionName){
        self::$_defaultConnection = $connectionName;
    }

    public static function getDefaultConnection(){
        if(is_null(self::$_defaultConnection)){
            $first = current(self::$_conncetionSettings);
            self::$_defaultConnection = $first['name'];
        }
        return self::$_defaultConnection;
    }
}

